package ui;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Group;

public class ProfileInformation extends Dialog {

	protected Object result;
	protected Shell shlLoadProfile;
	
	private boolean bExitFlag = false;
	private Shell parent_shell;
	private Text txtnoProfileLoaded;
	private Text text;
	private Text text_1;
	private Text text_2;
	private Text text_3;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public ProfileInformation(Shell parent, int style) {
		super(parent, style);
		setText("Confimation");
		parent_shell = parent;
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open(String _profileName) {
		createContents();
		shlLoadProfile.open();
		shlLoadProfile.layout();
		Display display = getParent().getDisplay();	
		Point location = parent_shell.getLocation();		// Get the location of the parent. *SR
		shlLoadProfile.setLocation(location.x+68, location.y+26);
		
		Group grpDescription = new Group(shlLoadProfile, SWT.NONE);
		grpDescription.setText("Profile Description");
		grpDescription.setBounds(10, 10, 334, 210);
		
		txtnoProfileLoaded = new Text(grpDescription, SWT.BORDER);
		txtnoProfileLoaded.setText("(No Profile Loaded)");
		txtnoProfileLoaded.setEditable(false);
		txtnoProfileLoaded.setFont(SWTResourceManager.getFont("Times New Roman", 11, SWT.NORMAL));
		txtnoProfileLoaded.setBounds(74, 34, 250, 21);
		
		Label lblName = new Label(grpDescription, SWT.NONE);
		lblName.setText("Name:");
		lblName.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.NORMAL));
		lblName.setBounds(10, 29, 58, 28);
		
		Group group = new Group(grpDescription, SWT.NONE);
		group.setText("Dosage Breakdown");
		group.setBounds(10, 76, 314, 124);
		
		Label label = new Label(group, SWT.NONE);
		label.setText("12AM-4AM:");
		label.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.NORMAL));
		label.setBounds(10, 34, 76, 28);
		
		Label label_1 = new Label(group, SWT.NONE);
		label_1.setText("4AM-6AM:");
		label_1.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.NORMAL));
		label_1.setBounds(10, 68, 76, 28);
		
		Label label_2 = new Label(group, SWT.NONE);
		label_2.setText("6AM-10AM:");
		label_2.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.NORMAL));
		label_2.setBounds(167, 34, 76, 28);
		
		Label label_3 = new Label(group, SWT.NONE);
		label_3.setText("10AM-12AM:");
		label_3.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.NORMAL));
		label_3.setBounds(167, 68, 76, 28);
		
		text = new Text(group, SWT.BORDER);
		text.setEditable(false);
		text.setBounds(92, 33, 55, 21);
		
		text_1 = new Text(group, SWT.BORDER);
		text_1.setEditable(false);
		text_1.setBounds(92, 67, 55, 21);
		
		text_2 = new Text(group, SWT.BORDER);
		text_2.setEditable(false);
		text_2.setBounds(249, 33, 55, 21);
		
		text_3 = new Text(group, SWT.BORDER);
		text_3.setEditable(false);
		text_3.setBounds(249, 67, 55, 21);
		
		if (_profileName == "No Exercise") { text.setText("0.5"); text_1.setText("0.7"); text_2.setText("0.6"); text_3.setText("0.5"); txtnoProfileLoaded.setText("No Exercise"); }
		else if (_profileName == "Light Exercise") { text.setText("0.5"); text_1.setText("0.7"); text_2.setText("0.6"); text_3.setText("0.5"); txtnoProfileLoaded.setText("Light Exercise"); }
		else if (_profileName == "Heavy Exercise") { text.setText("0.4"); text_1.setText("0.6"); text_2.setText("0.5"); text_3.setText("0.4"); txtnoProfileLoaded.setText("Heavy Exercise"); }
		
		Button btnLoad = new Button(shlLoadProfile, SWT.NONE);
		btnLoad.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				bExitFlag = true;
			}
		});
		btnLoad.setBounds(269, 231, 75, 45);
		btnLoad.setText("OK");
		while (!shlLoadProfile.isDisposed() && bExitFlag == false) { // *SR
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		shlLoadProfile.dispose(); // *SR
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlLoadProfile = new Shell(getParent(), getStyle());
		shlLoadProfile.setSize(360, 284);
		shlLoadProfile.setText("Profile Details");

	}
}
